package com.qd.panda.etc.dto.constant;

import com.cdqidi.exception.ApiException;
import lombok.Data;
import lombok.ToString;
import lombok.experimental.Accessors;
import lombok.extern.slf4j.Slf4j;

import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.stream.Collectors;

/**
 * @author sjk
 * 车牌颜色
 * 蓝色 0
 * 黄色 1
 * 黑色 2
 * 白色 3
 * 渐变绿色 4
 * 黄绿双拼色 5
 * 蓝白渐变色 6
 * 临时牌照 7
 * 未确定 9
 * 绿色 11
 * 红色 12
 * @author sjk
 */
@Slf4j
public class VehicleColorConstant {

    private static final List<VehicleColor> LIST = new ArrayList<>(11);
    private static final List<Integer> CODE;
    private static final Map<Integer, String> MAP = new HashMap<>(11);

    static {
        LIST.add(new VehicleColor().setCode(0).setName("蓝色"));
        LIST.add(new VehicleColor().setCode(1).setName("黄色"));
        LIST.add(new VehicleColor().setCode(2).setName("黑色"));
        LIST.add(new VehicleColor().setCode(3).setName("白色"));
        LIST.add(new VehicleColor().setCode(4).setName("渐变绿色"));
        LIST.add(new VehicleColor().setCode(5).setName("黄绿双拼色"));
        LIST.add(new VehicleColor().setCode(6).setName("蓝白渐变色"));
        LIST.add(new VehicleColor().setCode(7).setName("临时牌照"));
        LIST.add(new VehicleColor().setCode(9).setName("未确定"));
        LIST.add(new VehicleColor().setCode(11).setName("绿色"));
        LIST.add(new VehicleColor().setCode(12).setName("红色"));

        CODE = LIST.stream().map(VehicleColor::getCode).collect(Collectors.toList());
        LIST.forEach(vehicleColor -> MAP.put(vehicleColor.getCode(), vehicleColor.getName()));
    }

    public static List<VehicleColor> getVehicleColor() {
        return LIST;
    }

    public static void checkCode(Integer code) {
        if (!CODE.contains(code)) {
            throw new ApiException("颜色错误");
        }
    }

    public static String idToDisplay(Integer vehicleColor) {
        return MAP.getOrDefault(vehicleColor, "");
    }

    public static void main(String[] args) {
       log.info(idToDisplay(0));
    }
}

@Data
@Accessors(chain = true)
@ToString
class VehicleColor {
    private Integer code;
    private String name;

    public void freeData() {
        this.code = null;
        this.name = null;
    }
}